<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Symfony\Component\HttpFoundation\Response;

class CheckBannedMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next): mixed
    {
        if(!is_null(auth('admin')->user())) {
            if (auth('admin')->user() ->status=== 0) {
                Auth::logout(); // 登出用户
                return redirect()->back()->withErrors([
                    'error' => '您的账户已被禁用，请联系管理员。',
                ]);

            }
        }

        return $next($request);
    }

}
